<?php

class rsrequest_item {
	function respone_form($object, $request) {
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();

		$form = new form();
		if (!isset($object->id)) {
			$object->content = '';
		} else {
			$form->meta('id',$object->id);
		}
        //$config->remove_body_html=1;
		$form->register('content','Trả lời yêu cầu',new texteditorcontrol($object->content,3,60,true));
		$form->register('submit','',new buttongroupcontrol('Save'));
		return $form;
	}

    /**
    * This function save the public submit request
    * 
    * @param mixed $values
    * @param mixed $object
    * @author: trungdt
    */
    function publicrequest_save($values,$object) {
        global $db;
        $lang = exponent_lang_loadFile('datatypes/rsrequest_item.php');
        
        $object->fullname=_ab_safe_html_string($values['fullname']);
        $object->phone=_ab_safe_html_string($values['phone']);
        $object->email=_ab_safe_html_string($values['email']);
        
        // trade type
        $temp=intval($values['tradetype']);
        if (isset($lang["trade_type{$temp}"]))
        {
            $temp=$lang["trade_type{$temp}"];
        }
        else
        {
            $temp=$lang["unknown"];
        }
        $ret.="<div><b>Nhu cầu</b>: ".$temp."</div>";
        
        // bdstype 
        $temp=intval($values['bds_type']);
        if (isset($lang["bds_type{$temp}"]))
        {
            $temp=$lang["bds_type{$temp}"];
        }
        else
        {
            $temp=$lang["all"];
        }
        $ret.="<div><b>Loại bất động sản</b>: ".$temp."</div>";
        
        // huong 
        $temp=intval($values['huong']);
        if (isset($lang["direction_{$temp}"]))
        {
            $temp=$lang["direction_{$temp}"];
        }
        else
        {
            $temp=$lang["all"];
        }
        $ret.="<div><b>Hướng</b>: ".$temp."</div>";
        
        // tỉnh
        $temp=_ab_safe_html_string($values['province']);
        $temp=duanmodule::_GetProvince_byID($temp);
        //$temp=$db->selectObject("provinces", "short_name = '{$temp}' ");
        if ($temp==-1)
        {
            $temp=$temp=$lang["unknown"];
        }
        else
        {
            $temp=$temp->name;
        }
        $ret.="<div><b>Tỉnh </b>: ".$temp."</div>";
        
        // quận - huyện
        $temp=_ab_safe_html_string($values['ward']);
        $temp=duanmodule::_GetWard_byID($temp);
        //$temp=$db->selectObject("provinces_wards", "shortname = '{$temp}' ");
        if ($temp==-1)
        {
            $temp=$temp=$lang["all"];
        }
        else
        {
            $temp=$temp->name;
        }
        $ret.="<div><b>Quận-Huyện </b>: ".$temp."</div>";
        
        // huong 
        $temp=intval($values['price']);
        if (isset($lang["price_{$temp}"]))
        {
            $temp=$lang["price_{$temp}"];
        }
        else
        {
            $temp=$lang["unknown"];
        }
        $ret.="<div><b>Khoảng giá</b>: ".$temp."</div>";
        
        // other comments
        
        $ret.="<div><b>Ghi chú khác</b>: ".$values['other_comment']."</div>";
        //
        $object->content=$ret;
        $object->request_type=0;
        $object->request_date=time();
        $object->user_id=-1;
        if (exponent_users_isLoggedIn())
        {
            global $user;
            $object->user_id=$user->id;
        }
        $object->unread=0;
        $object->admin_unread=1;
        return $object;
    }
    
	function update($values,$object) {
		$object->name = $values['name'];
		$object->url = $values['url'];
		$object->file_id = $values['file_id'];
		$object->opennew = (isset($values['opennew']) ? 1 : 0);
		$object->description = $values['description'];
		return $object;
	}
}

?>